﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Hedgehog
{
    class Ellipse : IFigure
    {
        private int _x;
        private int _y;
        private int _a;
        private int _b;
        public  int offsetX {get;set;}
        public int offsetY { get; set; }
       
       public Ellipse( int X, int Y,int A,int B) 
       {
           _x = X;
           _y = Y;
           _a = A;
           _b = B;
       }

       public void Draw(Graphics g)
       {

           bool firstIteration = true;
           int lastX = 0;
           int lastY = 0;
           for (double t = 0; t <= Math.PI*2 + 0.1; t += 0.1)
           {
               int newX = (int) (_a*Math.Sin(t)) + _x + offsetX;
               int newY = (int) (_b*Math.Cos(t)) + _y + offsetY;

               if (firstIteration)
               {

                   lastX = newX;
                   lastY = newY;
                   firstIteration = false;
                   continue;
               }

               g.DrawLine(Pens.Black, lastX, lastY, newX, newY);
               lastX = newX;
               lastY = newY;
           }
       }

        public bool ChekIfPointInside(int x, int y)
       {
           bool pointInside = false;
           if (x > -_a + _x + offsetX && x < _a + _x + offsetX && y > -_b + _y + offsetY && y < _b + _y + offsetY)
               pointInside = true;
           return pointInside;
       }

        public object Clone()
        {
            return new Ellipse(_x,_y,_a,_b);
        }
    }
}
